use std::fs::File;
use serde::{Deserialize, Serialize};
use anyhow::{bail, Result};
use clap::Parser;
use tracing::info;

#[derive(Debug, Serialize, Deserialize)]
pub struct AppConfig {
    pub server: ServerConfig,
    pub auth: AuthConfig,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PlatformType {
    pub target_os: String
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ServerConfig {
    pub host: String,
    pub port: u16,
    pub db_url: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AuthConfig {
    pub sk: String,
    pub pk: String,
}

impl AppConfig {
    pub fn load(path: String) -> Result<Self> {
        info!("app config path : {}", path);
        let fs = File::open(path)?;
        let ret = serde_yaml::from_reader(fs)?;
        Ok(ret)
    }
}